package com.linkoog.devtools.generate.method_creater.dialog;

import com.linkoog.devtools.generate.method_creater.domain.ControllerMethodVo;
import com.linkoog.devtools.utils.Assert;

import javax.swing.*;

public class ControllerMethodPanel {

    private JPanel myMainPanel;
    private JComboBox httpMethodComboBox;
    private JTextField httpUrlTextField;

    private JPanel docPanel;
    private JTextField apiNameTextField;
    private JTextField apiRemarkTextField;

    private JTextField methodNameTextField;
    private JTextField methodParamTextField;
    private JTextField methodReturnTextField;


    private JPanel previewPanel;
    private JScrollPane methodContextPanel;



    public ControllerMethodPanel() {
        httpUrlTextField.setText("/");
        methodNameTextField.setText("getData");
        methodReturnTextField.setText("Result");
        initHttpMethodSelectBox();
    }

    private void initHttpMethodSelectBox(){
        final DefaultComboBoxModel model = new DefaultComboBoxModel();
        model.addElement("GET");
        model.addElement("POST");
        model.addElement("PUT");
        model.addElement("DELETE");
        httpMethodComboBox.setModel(model);
    }

    public void getConfig(ControllerMethodVo vo){
        String httpMethod = (String)httpMethodComboBox.getSelectedItem();
        vo.setHttpMethod(httpMethod);

        String httpUrl = httpUrlTextField.getText();
        Assert.hasText(httpUrl, "url不能为空");
        vo.setHttpUrl(httpUrl);

        String apiName = apiNameTextField.getText();
        vo.setApiName(apiName);

        String apiRemark = apiRemarkTextField.getText();
        vo.setApiRemark(apiRemark);

        vo.setMethodVisibility("public");

        String methodName = methodNameTextField.getText();
        Assert.hasText(methodName, "方法名不能为空");
        vo.setMethodName(methodName);

        String methodReturn = methodReturnTextField.getText();
        Assert.hasText(methodReturn, "返回值不能为空");
        vo.setMethodReturn(methodReturn);
    }

    public JPanel getMyMainPanel() {
        return myMainPanel;
    }
}
